package gui;

import java.awt.Dialog.ModalityType;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import model.Stack;

public class Notification extends JDialog {
	private JLabel label;
	private JTextArea textException;
	private JScrollPane textExceptionScroll;
	
	private Notification() {
	}
	
	public Notification(Stack s) {
		label = new JLabel(s.toString() + " is about to exceed available process time.");
		label.setSize(500, 20);
		label.setLocation(20, 20);
		this.add(label);
		
		this.setModalityType(ModalityType.APPLICATION_MODAL);
		this.setSize(500, 100);
		this.setTitle("Stack process time alert");
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.setLocation(300, 150);
		this.setLayout(null);
		this.setVisible(true);
	}
	
	public Notification(Exception e) {
		this(e, null);
	}
	
	public Notification(Exception e, String message) {
		label = new JLabel(e.getClass().getSimpleName() + ": " + e.getMessage());
		label.setSize(300, 20);
		label.setLocation(5, 0);
		this.add(label);
		
		textException = new JTextArea(ExceptionHandler.buildStackTraceString(e.getStackTrace()));
		textException.setLocation(5, 25);
		textException.setSize(290, 370);
		this.add(textException);
		textExceptionScroll = new JScrollPane(textException);
		textExceptionScroll.setBounds(5, 30, 290, 365);
		this.add(textExceptionScroll);
		
		this.setModalityType(ModalityType.APPLICATION_MODAL);
		this.setSize(317, 439);
		this.setLocation(300, 150);
		this.setTitle(message != null ? message : "Application has generated a checked exception");
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.setLayout(null);
		this.setVisible(true);
	}
}